package com.bailian.core.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;

import java.util.ArrayList;
import java.util.List;

public class BindExceptionUtil {

    /**
     * 获取批量异常信息
     *
     * @return
     */
    public static String getMessage(MethodArgumentNotValidException e) {
        List<String> msgList = new ArrayList<>();
        for (ObjectError objectError : e.getBindingResult().getAllErrors()) {
            msgList.add(objectError.getDefaultMessage());
        }
        return StringUtils.join(msgList.toArray(), ",");
    }

}